<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('基础数据列表')" />
    <style type="text/css">
		label.layui-form-label {padding-right: 0px;}
        /*.main-container{}*/
        .main-content{margin-left: 0;min-height: 100%;padding: 0;margin-top: 16px;background: #FFFFFF;border-right: 16px solid #f2f2f2;}
        .main-container:before{display:block;content:"";position:absolute;z-index:-2;width:100%;max-width:inherit;bottom:0;top:0;background-color:#f2f2f2}
	</style>
</head>
<body class="no-skin">
 <div class="main-container" id="main-container">
    <div class="main-content">
        <div class="north">
            <div class="north-content">
                <form>
					<th:block th:include="listinclude :: searchTop" />
				</form>
            </div>
        </div>
        <div class="mid-content" style="margin-top: -16px;">
            <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
        </div>
    </div>
 </div>
 <script type="text/html" id="barDh">
    <a class="layui-btn layui-btn-xs dhicon dh-edit" lay-event="edit"  shiro:hasPermission="logstics:logisticsmmode:edit">&nbsp;编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" lay-event="del" shiro:hasPermission="logstics:logisticsmmode:delete">&nbsp;删除</a>
 </script>
 <script type="text/html" id="toolbar1">
    <div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" lay-event="addbtn" shiro:hasPermission="logstics:logisticsmmode:add">
            <p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span" style="color: #FFFFFF">新增</span></p>
        </div>
    </div>
 </script>
 <script type="text/html" id="templet_bdefaulttext">
    <input type="checkbox" value="{{d.guid}}" lay-skin="switch" lay-text="是|否" name="bdefault" lay-filter="change" {{ d.bdefault? 'checked' : '' }}>
</script>
 <th:block th:include="include :: footer" />
 <script th:inline="javascript">
     /*<![CDATA[*/
     var vtype = [[${vtype}]];
     var type = [[${type}]];
     var gridColumns = [[${gridColumns}]];
     var k_fields =[[${fields}]];
     var moduleTable=[[${moduleTable}]];
     /*]]>*/
 </script>
 <script type="text/javascript">
 var $,layer,form,table,wherestr={};
    layui.use(['table','form','layer','jquery'], function () {
    	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table;
        $.tablelist.init({
            elem: '#dhtable'
            ,url: "/logstics/logisticsmmodegrads/list?type="+type
        	,totalRow: gridColumns.totalRow
            ,cols: [gridColumns.gridBody
            ]
            ,toolbar: '#toolbar1'
            ,defaultToolbar:[]
            ,height:'full-' + ( $('.north').height()+52),
        });
        //监听表格排序问题
        table.on('sort(ftable)', function (obj) {
            table.reload('dhtable', { //dhtableTable是表格容器id
                initSort: obj,
                where: {
                    field: obj.field //排序字段
                    ,order: obj.type //排序方式
                }
            });
        });
      	// //监听开关动作
     	// form.on('switch(change)', function(obj){
     	// 	var data={};
     	// 	data['guid']=obj.value;
     	// 	data['vtype']=vtype;
     	// 	if(obj.elem.checked==true){
     	// 		data[obj.elem.name]=1;
      	//     	$.operate.post("/logstics/logsticsinfo/editbdefaultpost", {'logisticsmmodeInfoItems':JSON.stringify([data])},function(result){
        //             allReload(result)
        //         });
        // 	}else{
        // 		data[obj.elem.name]=0;
    	//     	$.operate.post("/logstics/logsticsinfo/editbdefaultpost", {'logisticsmmodeInfoItems':JSON.stringify([data])});
    	//     }
        // });
        //头工具栏事件
        table.on('toolbar(ftable)', function(obj){
            switch(obj.event){
                case 'addbtn':
                    dialog('新增','/logstics/logisticsmmodegrads/add?type='+type+'&moduleTable=TP_LogisticsMmodeGrads'+"_"+type,$(window).width()-300,$(window).height()-250,'addpost');
                    break;
            };
        });
        //监听工具条
        table.on('tool(ftable)', function (obj) {
            var data = obj.data;
            if(obj.event === 'del'){ //删除
                $.modal.confirmCom('确定要删除么？',function(){
                    $.operate.post('/logstics/logisticsmmodegrads/deletepost',{'logisticsmmodeInfoItems':JSON.stringify([{'guid':data.guid}])},function(result){
                        allReload(result)
                    });
                });
            }else if (obj.event === 'edit') {
                dialog('编辑','/logstics/logisticsmmodegrads/edit?guid='+ data.guid+'&moduleTable=TP_LogisticsMmodeGrads'+"_"+type,$(window).width()-300,$(window).height()-250,'editpost');
            }
        });
      	//搜索按钮
     	$('#btn-search').on('click', function () {
     		$.each(wherestr,function(i,v){$("#"+i).val()?wherestr[i]=$("#"+i).val():wherestr[i]='';});//动态获取条件的值
            table.reload('dhtable', {page: {curr: 1},where:wherestr});
         });
     	//监听下拉框——添加条件
     	form.on('select(fft)', function(obj){
     		addMore(this);
     	});
        function dialog(title,url,width,height,Method){
            $.modal.open(title,url,width,height,function(index){
                var inputForm = $(window.frames["layui-layer-iframe" + index].document).contents().find(".layui-form");
                var is_return = 0,
                    postStr = [],
                    must_field={},
                    Str = inputForm.serializeFormToJson();

                $.each(k_fields,function (fk,fv) {
                    if(fv.fieldFrontRequired)
                        must_field[fv.fields] = fv.fieldName + " 不能为空";
                })
                $.each(must_field,function (k,v) {
                    if(!inputForm.find("#"+k).val()){
                        layer.msg(v);
                        is_return = 1;
                        inputForm.find("#"+k).css('border','1px solid red');
                        inputForm.find("#"+k).focus()
                        return false;
                    }
                })
                if(is_return)return false;
//                 if(!inputForm.find("#bdeleted").is(':checked')){Str['bdeleted'] = '1';}		//CheckBox 默认值0:启用,1:禁用 ;选中为0
                postStr.push(Str);
                let url;
                if (Str.guid == null || Str.guid == ''){
                    url = "addpost";
                } else {
                    url = "editpost";
                }
                $.operate.post("/logstics/logisticsmmodegrads/"+url, {'logisticsmmodegrads':JSON.stringify(postStr)},function(result){
                    allReload(result)
                });
            })
        }
        function allReload(result){
            if(result.code==0){
                setTimeout(function(){
                    layer.closeAll();
                    table.reload('dhtable');
                }, 1000);
            }
        }

    });
</script>
</body>
</html>